//用mock对象来模拟我们系统中的top对象
// import mock from '../mock'
let ajax = top.ajaxRequest;

export default {

    //获取大屏监控系统欢迎语
    getWelcomeMsg(){
        // return mock.njs.requestSysparam("SM_WELCOME");
        return top.njs.requestSysparam("SM_WELCOME");
    },

    //根据媒体类型查询实时排队数
    getLineUpByMedia(){
        return new Promise((resolve, reject)=>{
            top.CallManage.UCC.getLineUpByMedia([1,5],['IDX_09_01_002'],1,(result)=>{
                if(result.length == 2){
                    let obj = {};
                    obj.w = result[0].idxs[0].val;
                    obj.v = result[1].idxs[0].val;
                    resolve(obj);
                }else{
                    reject()
                }

            })
        })
    },

    //根据媒体类型查询历史数据
    getHistoryByMedia(){
        return new Promise((resolve, reject)=>{
            top.CallManage.UCC.getHistoryByMedia([1,5],
                [
                    "IDX_09_04_001",	//请求人工数（接入量）
                    "IDX_09_04_002",	//通话量（会话量）
                    "IDX_09_05_001",	//通话率（接通率）
                    "IDX_09_06_005",	//通话均长（平均通话时长）
                    "IDX_09_06_006" 	//等待均长（平均等待时长）
                ],
                (result)=>{

                if(result.length == 2){
                    var obj = {};
                    obj.voiceTimes = result[1].idxs[1].val
                    obj.voiceTotal = result[1].idxs[0].val
                    obj.voiceALTime = result[1].idxs[3].val
                    obj.voiceAWTime = result[1].idxs[4].val
                    obj.onlineTotal = result[0].idxs[0].val
                    obj.onlineRate = result[0].idxs[2].val
                    obj.onlineAcAm = result[0].idxs[1].val
                    resolve(obj)
                }else{
                    reject()
                }

            })
        })
    },

    //IVR来源统计
    getIvrsource(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101903',
                }],
                func:function(data){
                    let result = {};
                    result.columns = ['CHNL_BIZ_NAME','ACCS_CNT'];
                    result.rows = data[0];
                    resolve(result)
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //渠道接通量
    getChannelAccess(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101906',
                }],
                func:function(data){
                    let result = {};
                    result.columns = ['渠道', '接入量'];
                    data[0].forEach((item)=>{
                        item['接入量'] = item['ACCS_CNT']
                    })
                    result.rows = data[0];
                    resolve(result)
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //当日服务累计
    getTodayTotal(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18102301',
                }],
                func:function(data){
                    let result = {};
                    result.columns = ['TYPE_NAME','ACCS_CNT'];
                    result.rows = data[0];
                    resolve(result)
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //24小时话务监控
    getAllhoursmon(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101904',
                }],
                func:function(data){
                    let result = {};
                    result.columns = ['时刻', '总话务量', '语音应答','客户接通','呼损量'];
                    result.rows = data[0];
                    data[0].forEach((item)=>{
                        item['时刻'] = item['M_TIME']
                        item['总话务量'] = item['NUMS_ALL_CALL']
                        item['语音应答'] = item['NUMS_VOICE_ANS_CALL']
                        item['客户接通'] = item['NUMS_CUST_SUCC_CALL']
                        item['呼损量'] = item['NUMS_LOSS_CALL']
                    })
                    resolve(result)
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //当前实时话务
    getRealTime(){
        return new Promise((resolve, reject)=>{
            top.CallManage.UCC.getRealTimeVdn([1],
            [
                'IDX_01_04_001',    //通话数（客户呼入）
                'IDX_01_04_002',    //IVR处理数（IVR）
                'IDX_01_04_100'     //外呼数【待增加】（坐席呼出）
            ],
            (result)=>{
                if(result){
                    resolve(result)
                }else{
                    reject()
                }

            })
        })
    },
    getRealTime2(){
        return new Promise((resolve, reject)=>{
            top.CallManage.UCC.getLineUpByMedia([1],
                [
                    'IDX_09_01_003'    //正在处理呼叫数(在线服务)
                ],1,
                (result)=>{
                    if(result){
                        resolve(result)
                    }else{
                        reject()
                    }

                })
        })
    },


    //在线话务监控
    getOnlinemon(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101905',
                }],
                func:function(data){
                    let result = {};
                    // result.columns = ['M_TIM', 'NUMS_QUEUE','NUMS_ONLINE_SERV','NUMS_NOT_ACCESS'];['时刻', '排队数','服务数','未接入量']
                    data[0].forEach((item)=>{
                        item['时刻'] = item['M_TIM']
                        item['排队数'] = item['NUMS_QUEUE']
                        item['服务数'] = item['NUMS_ONLINE_SERV']
                        item['未接入量'] = item['NUMS_NOT_ACCESS']
                    })
                    result.rows = data[0];
                    resolve(result)
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //获取所有的技能队列
    getAllSkills(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U2003801',
                }],
                func:function(data){
                    if(data[0]){
                        resolve(data[0])
                    }
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //查询技能队列监控信息
    getHistorySkillInfo(skills){
        return new Promise((resolve, reject)=>{
            top.CallManage.UCC.getHistorySkillInfo(skills,
                [
                    "IDX_03_04_001",	//请求人工数（呼入/在线数量）
                    "IDX_03_04_002",	//通话量（接通数）
                    "IDX_03_05_001",	//通话率（接通率）
                    "IDX_03_06_005",	//通话均长（平均服务时长）
                    "IDX_03_06_006",	//等待均长（平均等待时长）"IDX_03_04_001"

                ],
                (result)=>{
                    if(result){
                        resolve(result)
                    }else{
                        reject()
                    }

                })
        })
    },

    //实时技能队列监控指标接口基本信息
    getRealtimeSkillInfo(skills){
        return new Promise((resolve, reject)=>{
            top.CallManage.UCC.getRealtimeSkillInfo(skills,
                [
                    "IDX_03_01_002",	//排队数
                ],
                (result)=>{
                    if(result){
                        resolve(result)
                    }else{
                        reject()
                    }

                })
        })
    },

    //获取当日坐席接听量
    getRanking(max){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101901',
                    MAX_CNT:max
                }],
                func:function(data){
                    if(data[0]){
                        resolve(data[0])
                    }
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //获取总计信息
    getHistoryByVnd(){
        return new Promise((resolve, reject)=>{
            top.CallManage.UCC.getHistoryByVnd([1],
                [
                    "IDX_01_02_001",	//请求人工数（呼入/在线数量）
                    "IDX_01_02_002",	//通话量（接通数）
	                "IDX_01_02_003",	//通话率（接通率）
	                "IDX_01_02_012",	//通话均长（平均服务时长）
	                "IDX_01_02_013",	//等待均长（平均等待时长）
                ],
                (result)=>{
                    if(result){
                        resolve(result)
                    }else{
                        reject('/indicators/history/vdn 接口出错')
                    }

                })
        })
    },

    //获取来电分布数据
    getDistribution(max){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101902',
                    MAX_CNT:max
                }],
                func:function(data){

                    if(data[0]){
                        resolve(data[0])
                    }
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //渠道接入统计
    getChannelAccCnt(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101906',
                    SKILL_MEDIA_TYPE:5  //在线
                }],
                func:function(data){
                    if(data[0]){
                        resolve(data[0])
                    }
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    },

    //渠道接通率统计
    getChannelAccRat(){
        return new Promise((resolve, reject)=>{
            ajax({
                req:[{
                    service:'U18101907',
                    SKILL_MEDIA_TYPE:5  //在线
                }],
                func:function(data){
                    if(data[0]){
                        data[0].forEach((item)=>{
                            item['key'] = item['CHNL_BIZ_NAME']
                            item['val'] = item['ACCS_RATE']
                        })
                        resolve(data[0])
                    }
                },
                error:function (err) {
                    reject(err)
                }
            })
        })
    }

}
